package com.lzb.compressmaster;

import android.content.Intent;
import android.graphics.Color;
import android.view.View;

import androidx.annotation.NonNull;

import com.lzb.compressmaster.activity.WebActivity;
import com.lzb.compressmaster.databinding.ActivityHomeBinding;
import com.lzb.compressmaster.fragment.CompressFragment;
import com.lzb.compressmaster.fragment.DecompressFragment;
import com.lzb.compressmaster.fragment.HomeFragment;
import com.lzb.compressmaster.fragment.MyFragment;
import com.sztle.admodule.IEnterHomeCallback;
import com.sztle.admodule.apiprocessor.OutIntAdApi;
import com.sztle.admodule.outstatus.AppStatusProcessor;

import java.util.ArrayList;
import java.util.List;

public class HomeActivity extends BaseTabFragmentHomeActivity<ActivityHomeBinding> {

    @Override
    protected void initView() {
        super.initView();

        //todo list 到达主页面acitivty,需标记
        AppStatusProcessor.statusEnterHome(this, new IEnterHomeCallback() {
            @Override
            public void onClickUserPolicy() {
                //todo list 跳转用户协议，开发者自定义跳转页面及方式
                Intent bundle = new Intent(HomeActivity.this, WebActivity.class);
                bundle.putExtra("type", 0);
                startActivity(bundle);
            }

            @Override
            public void onClickPrivacyPolicy() {
                //todo list 跳转隐私政策，开发者自定义跳转页面及方式
                Intent bundle = new Intent(HomeActivity.this, WebActivity.class);
                bundle.putExtra("type", 1);
                startActivity(bundle);
            }
        });

    }

    @Override
    protected int onCreate() {
        return R.layout.activity_home;
    }

    @NonNull
    @Override
    protected List<BaseTabFragmentHomeActivity<ActivityHomeBinding>.FragmentViewBinder> getFragmentViewBinders() {
        List<FragmentViewBinder> listFragment = new ArrayList<>();
        listFragment.add(new FragmentViewBinder(HomeFragment.class, R.id.llHome));
        listFragment.add(new FragmentViewBinder(CompressFragment.class, R.id.llCompress));
        listFragment.add(new FragmentViewBinder(DecompressFragment.class, R.id.llDecompress));
        listFragment.add(new FragmentViewBinder(MyFragment.class, R.id.llMy));
        return listFragment;
    }

    @Override
    protected void onFragmentViewClick(View view) {
        clearSelection();
        int id = view.getId();
        if (id == R.id.llHome) {
            mDataBinding.ivHome.setImageResource(R.drawable.aawj);
            mDataBinding.tvHome.setTextColor(Color.parseColor("#246FFE"));
        } else if (id == R.id.llCompress) {
            mDataBinding.ivCompress.setImageResource(R.drawable.aays);
            mDataBinding.tvCompress.setTextColor(Color.parseColor("#246FFE"));
        } else if (id == R.id.llDecompress) {
            mDataBinding.ivDecompress.setImageResource(R.drawable.aajy);
            mDataBinding.tvDecompress.setTextColor(Color.parseColor("#246FFE"));
        } else if (id == R.id.llMy) {
            mDataBinding.ivMy.setImageResource(R.drawable.aagrzx);
            mDataBinding.tvMy.setTextColor(Color.parseColor("#246FFE"));
        }

        OutIntAdApi.showSingleIntAd(this, "tab");
    }

    @Override
    protected int getFragmentContainerId() {
        return R.id.flContainer;
    }

    private void clearSelection() {
        mDataBinding.ivHome.setImageResource(R.drawable.awj);
        mDataBinding.tvHome.setTextColor(Color.parseColor("#999999"));
        mDataBinding.ivCompress.setImageResource(R.drawable.ays);
        mDataBinding.tvCompress.setTextColor(Color.parseColor("#999999"));
        mDataBinding.ivDecompress.setImageResource(R.drawable.ajy);
        mDataBinding.tvDecompress.setTextColor(Color.parseColor("#999999"));
        mDataBinding.ivMy.setImageResource(R.drawable.agrzx);
        mDataBinding.tvMy.setTextColor(Color.parseColor("#999999"));
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        //todo list 热启动到达主页面，需标记
        AppStatusProcessor.statusOnIntentHome(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        //todo list 主页面onStop,需标记
        AppStatusProcessor.statusStopHome();
    }

}